import Taro from "@tarojs/taro";
import { sg } from "@utils/index";

export const $route = (opts: RouterOptions) => {
  const { url, type = "navigateTo", delta, appId } = opts;
  console.log("opts", opts);
  if (appId) {
    Taro.navigateToMiniProgram({
      appId,
      path: url,
    });
    return false;
  }
  if (url) {
    if (url.startsWith("http")) {
      sg.set("webviewUrl", url);
      Taro[type]({ url: "/pages/webview/index" });
      return false;
    }
    Taro[type]({ url });
  } else if (delta) {
    Taro.navigateBack({ delta });
  }
};
$route.back = (delta: number = 1) => {
  Taro.navigateBack({ delta });
};
